package control;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.National;
public class EditNational extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public EditNational() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String n_name = request.getParameter("nn");
		String pt = request.getParameter("pt");
		String uid = request.getParameter("uid");
		
		National national = new National(0, Integer.parseInt(uid), n_name, Integer.parseInt(pt));
		System.out.println(national.toString());
		if (national.checkNewName()!="") {
			request.setAttribute("enn",national.checkNewName());
			request.setAttribute("pt",national.getPosition());
			RequestDispatcher transferexist = getServletContext().getRequestDispatcher("/a/national.jsp?site=e");
			transferexist.forward(request, response);
		} else {
			if(national.upDate()==false){
			request.setAttribute("m", "err-editna");
			request.setAttribute("r","vn");
			RequestDispatcher transfer = getServletContext().getRequestDispatcher("/a/message.jsp");
			transfer.forward(request, response);
			}
			else{
				request.setAttribute("m", "edit-naok");
				request.setAttribute("r","a");
				RequestDispatcher transfer = getServletContext().getRequestDispatcher("/a/message.jsp");
				transfer.forward(request, response);
			}
		}
	}

}
